﻿namespace GSC.WebControls
{
    using System;
    using System.ComponentModel;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    /// <summary>
    /// BackgroundHeadControl HeadLogout 默认模板。
    /// </summary>
    /// <remarks>BackgroundHeadControl HeadLogout 默认模板。</remarks>
    sealed class BackgroundHeadControlLogoutDefaultTemplate : ITemplate
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="owner"></param>
        void ITemplate.InstantiateIn(Control owner)
        {
            ImageButton Logout = new ImageButton();
            Logout.ID += "HeadLogout";
            Logout.CommandName = "HeadLogout";
            Logout.DataBinding += new EventHandler(this.dataBinding);
            owner.Controls.Add(Logout);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void dataBinding(object sender, EventArgs e)
        {
            ImageButton source = (ImageButton)sender;
            BackgroundHeadControl container = (BackgroundHeadControl)((TemplateTableCellOwner)source.NamingContainer).Owner;
            string l = System.Threading.Thread.CurrentThread.CurrentCulture.Name.Replace("-", "_");
            if (string.IsNullOrEmpty(container.LogoutImageUrl))
            {
                source.ImageUrl = container.GetWebResourceUrl(l + ".logout.gif");
            }
            else
            {
                source.ImageUrl = container.LogoutImageUrl;
            }
        }
    }
}